#include <vector>
#include <functional>

using std::vector;
using std::function;

class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int i = 0, j = nums.size() - 1;
        function<bool(int, int)> big = [=](int a, int b)->bool {
            if (b == 0) {
                return false;
            }
            else if (b == nums.size()) {
                return true;
            }
            else {
                return nums[a] > nums[b];
            }
            };
        while (i <= j) {
            int mid = (i + j) / 2;
            if (!big(mid - 1, mid) && big(mid, mid + 1)) {
                return mid;
            }
            else if (big(mid - 1, mid)) {
                j = mid - 1;
            }
            else {
                i = mid + 1;
            }
        }
        return i;
    }
};